/*******************************************************************************
 * Copyright (c) 2008, 2009 Fabio Mauro - Alberto Terraneo.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 1.2
 * or any later version published by the Free Software Foundation.
 *     
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Free Documentation License for more details.
 *     
 * You should have received a copy of the GNU Free Documentation 
 * License along with this distribution; if not, send a email to authors:
 * aterraneo <at> users.sourceforge.net
 * bigmoby09 <at> users.sourceforge.net
 *******************************************************************************/
package it.blueocean.acanto.web.platform.components.feedback;

import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.feedback.IFeedbackMessageFilter;

/**
 * Filter for accepting only feedback messages with this error level.
 *
 * You can use this code under Apache 2.0 license, as long as you retain the copyright messages.
 *
 * Tested with Wicket 1.3.4
 * @author Daan, StuQ.nl
 */
public class ErrorLevelsFeedbackMessageFilter implements IFeedbackMessageFilter
{
	private static final long serialVersionUID = -4022541601964514724L;

	/** The minimum error level */
	private int[] filteredErrorLevels;

	/**
	 * Constructor
	 * 
	 * @param filteredErrorLevels The FeedbackMessages that have these error levels will not be shown.
	 */
	public ErrorLevelsFeedbackMessageFilter(int[] filteredErrorLevels)
	{
		this.filteredErrorLevels = filteredErrorLevels;
	}

	/**
	 * Method accept, only accept FeedbackMessages that are not in the list of
	 * error levels to filter.
	 * 
	 * @param message of type FeedbackMessage
	 * @return boolean
	 */
	@Override
	public boolean accept(FeedbackMessage message)
	{
		for (int errorLevel : filteredErrorLevels)
		{
			if(message.getLevel() == errorLevel)
			{
				return false;
			}
		}

		return true;
	}

}
